package com.ruoyi.web.controller.mobile;

import cn.dev33.satoken.stp.StpUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shuati.domain.ShuatiQuestionBank;
import com.ruoyi.shuati.service.IShuatiQuestionBankService;
import com.ruoyi.shuati.vo.userBank.UserBankListVo;
import org.noear.socketd.SocketD;
import org.noear.socketd.transport.client.ClientSession;
import org.noear.socketd.transport.core.Listener;
import org.noear.socketd.transport.core.Message;
import org.noear.socketd.transport.core.Session;
import org.noear.socketd.transport.core.listener.EventListener;
import org.noear.socketd.transport.core.listener.SimpleListener;
import org.noear.socketd.transport.server.Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author liwenyan
 * @Date 2024/6/11 14:01
 * @PackageName:com.ruoyi.web.controller.shuati
 * @ClassName: ShuatiQuestionBankMobileController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/shuati/bank")
public class ShuatiQuestionBankMobileController extends BaseController {
    @Autowired
    private IShuatiQuestionBankService shuatiQuestionBankService;

    /**
     * 查询【当前用户创建的】列表
     */
    @GetMapping("/list")
    public TableDataInfo list() throws IOException {
        //启动服务
//        SocketD.createServer("sd:tcp")
//                .config(c -> c.port(8602).fragmentSize(1024*1024).sslContext(null))
//                .start();
        System.out.println("获取到的loginId " + StpUtil.getLoginId());
        UserBankListVo userBankListVo = new UserBankListVo();
        userBankListVo.setUserId((String) StpUtil.getLoginId());
        System.out.println("传递的 "+userBankListVo);
        startPage();
        List<ShuatiQuestionBank> list = shuatiQuestionBankService.selectMyBankList(userBankListVo);
        return getDataTable(list);
    }


    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(shuatiQuestionBankService.selectShuatiQuestionBankById(id));
    }

    /**
     * 新增【用户新增题库】
     */
    @PostMapping
    public AjaxResult add(@RequestBody ShuatiQuestionBank shuatiQuestionBank) {
        return toAjax(shuatiQuestionBankService.insertShuatiQuestionBank(shuatiQuestionBank));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ShuatiQuestionBank shuatiQuestionBank) {
        return toAjax(shuatiQuestionBankService.updateShuatiQuestionBank(shuatiQuestionBank));
    }

    /**
     * 删除【请填写功能名称】
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(shuatiQuestionBankService.deleteShuatiQuestionBankByIds(ids));
    }

}
